#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int sumBase(int n, int k) {
        int tmp = n;
        int I = 0;
        int count = 0;
        while (tmp)
        {
            int m = tmp % k;
            if (m)
            {
                count += pow(10, I++) * m;
                tmp -= m;
                continue;
            }
            else
            {
                tmp /= k;
            }
        }

        int re = 0;
        while (count)
        {
            re += count % 10;
            count /= 10;
        }

        //cout << re;

        return re;
    }
};